

module BeverageMaker
    require 'claide'
    require 'colored2'

    class Command < CLAide::Command
        require 'beverageMaker/command/tea'

        self.abstract_command = true

        self.description = 'Make delicious beverages from the comfort of your' \
        'terminal.'

        self.command = 'beverage-maker'

        def self.options
            [
                ['--no-milk', 'Don’t add milk to the beverage'],
                ['--sweetener=[sugar|honey]', 'Use one of the available sweeteners'],
            ].concat(super)
        end

        def initialize(argv)
            #是否添加牛奶，如果没有该选项 默认加牛奶
            @add_milk = argv.flag?("milk", true) 
            # 获取甜度参数
            @sweetener = argv.option("sweetner")
            super
        end

        def validate!
            super
            # 如果设置了甜度，且 不是 sugar 或者 honey，则 输出 help 
            if @sweetener && !%w(sugar honey).include?(@sweetener)
                help! "#{@sweetener} is not a valid sweetener"
            end
        end

        def run
            puts "* Boiling water ..."
            sleep 1
            if @add_milk
                puts "* Adding milk..."
                sleep 1
            end

            if @sweetener
                puts "* Add #{@sweetener}..."
            end
        end
    end
end